package edu.uwm.universitydb.swing;

import java.util.List;

import edu.uwm.universitydb.model.User;
import edu.uwm.universitydb.service.user.UserService;

public class UserTableModel extends DataTableModel {
	

	public UserTableModel(UserService service) {
		super(_colNames, _colTypes);
		_userService = service;
	}
	

	public UserService getService() {
		return _userService;
	}
	
	@Override
	public int getRowCount() {
		List<User> users = _userService.getAllUsers();
		return users.size();
	}
	@Override
	public Object getValueAt(int row, int col) {
		List<User> users = _userService.getAllUsers();
		switch (col) {
		case 0:
			return users.get(row).getUserName();
		case 1:
			return users.get(row).getRole().name();
		default:
			return "Error";
		}
		
	}
	
	private static final String[] _colNames = new String[] {"User","Role"};
	private static final Class<?>[] _colTypes = new Class<?>[] {String.class, String.class};
	
	private static final long serialVersionUID = 2650564265612683458L;


	private final UserService _userService;

}
